package com.xca.is.model;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.xca.is.entity.VideoEntity;
import com.xca.is.http.HttpConnect;
import com.xca.is.repository.VideoRepository;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class VideoModel extends ViewModel {
    private VideoRepository repository ;
    private MutableLiveData<VideoEntity> liveData  = new MutableLiveData<>();
    private HttpConnect httpConnect ;
    public VideoModel()
    {
        repository = null;
    }

    public void setData(HttpConnect httpConnect)
    {
        this.repository = new VideoRepository();
        this.httpConnect = httpConnect;
    }
    public void getData(){
        repository.getData()
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        Log.d("视频列表获取中", "开始获取");
                    }

                    @Override
                    public void onNext(@NonNull VideoEntity videoEntity) {
                        liveData.postValue(videoEntity);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        Log.d("视频列表获取失败", e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        Log.d("视频列表获取完成", "获取完成");
                    }
                });
    }
    public MutableLiveData<VideoEntity> getLiveData()
    {
        return liveData;
    }
}
